package org.brisling.ethic.service;

import java.util.List;

import org.brisling.base.domain.ListDomain;
import org.brisling.base.domain.RetDomain;
import org.brisling.common.ConstSysParam;
import org.brisling.common.util.StringUtil;
import org.brisling.ethic.domain.DicCategory;
import org.brisling.ethic.repository.DicCategoryRepo;
import org.brisling.ethic.service.base.BaseEthicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;


@RestController
@RequestMapping("/dicCategory")
/**
 * 用戶后台服務service
 * @Author : jackson wang
 * @Date   : 2015年6月8日 下午4:18:01
 * @version: 1.0
 */
public class DicCategoryService extends BaseEthicService<DicCategory>{
	
	@SuppressWarnings("unused")
	@Autowired
	private DicCategoryRepo baseRepo;
	
	public DicCategoryService(){
		this.moduleName = ConstSysParam.MODULE_ETHIC_DICCATEGORY;
		this.clazz = DicCategory.class;
	}
	
	/**
	 * 获取业务主页面 
	 * @return
	 */
	@RequestMapping("/mainPage.action")
	public ModelAndView getMainPage(){
		return new ModelAndView("/ethic/dic_category/main");
	}
	
	/* (non-Javadoc)
	 * @see org.brisling.service.sysman.DepartmentServiceInf#getEditPage()
	 */
	@RequestMapping("/editPage.action")
	public ModelAndView getEditPage(){
		return new ModelAndView("/ethic/dic_category/editDlg");
	}
	
	
	/**
	 * 分页查询用户列表页面
	 * @param deptid
	 * @param page
	 * @param rows
	 * @param sort
	 * @return
	 */
	@RequestMapping("/getListDomain.action")
	public ListDomain<DicCategory> getRoleListDomain(
			@RequestParam(value="page",required=false) String page,
			@RequestParam(value="rows",required=false) String rows,
			@RequestParam(value="sort",required=false) String sort){
		
				
		return super.getPagedList(page, rows);
			
	}
	
	/**
	 * 分页查询用户列表页面
	 * @param deptid
	 * @param page
	 * @param rows
	 * @param sort
	 * @return
	 */
	@RequestMapping("/getList.action")
	public List<DicCategory> getRoleList(
			@RequestParam(value="page",required=false) String page,
			@RequestParam(value="rows",required=false) String rows,
			@RequestParam(value="sort",required=false) String sort){
		
		
			return super.getAll(page,rows,getSort(sort));
			
	}
	
	/**
	 * 根据角色名称查找角色集合
	 * @param roleNames
	 * @return
	 */
	public List<DicCategory> getRoleListByRoleNames(List<String> roleNames){
		
		return super.getListByNames(roleNames);
			
	}
	
	/**
	 * 根据角色名称查找角色编码
	 * @param roleNames
	 * @return
	 */
	public List<String> getRoleIdsByRoleNames(List<String> roleNames){
		
		List<DicCategory> roles = this.getRoleListByRoleNames(roleNames);
		
		
		return StringUtil.getStringIdList(roles);
	}
	
	/**
	 * 删除人员信息
	 * @param id
	 */
	@RequestMapping("/del.action")
	public RetDomain delRow(@RequestParam(value="id",required=false) Long id){
		String retStr = super.del(id);
		
		RetDomain domain = new RetDomain();
		if(retStr=="200"){
			domain.setSuccessMsg("删除操作成功");
		}else{
			domain.setErrorMsg("删除操作失败");
		}
		return domain;		 
	}
	
	/**
	 * 删除人员信息
	 * @param id
	 */
	@RequestMapping("/flowDel.action")
	public RetDomain delFlowRow(@RequestParam(value="id",required=false) Long id){
		return delRow(id);
	}
	
	
	/**
	 * 删除组织节点
	 * @param id
	 */
	@RequestMapping("/save.action")
	public DicCategory save(@RequestBody String body){
		DicCategory role = bodyToObj(body, DicCategory.class);		
		super.save(role);
		return role;
	}
	
	
}
